import type { Router } from "express"
import type { Ioracle, IcallbackFn } from "../../types"

export default (router: Router, oracle: Ioracle, callbackFn: IcallbackFn) => {
  //抓取固定资产资料
  router.post("/getAssetData", (req, res) => {
    const { orgCode, deptCode, assetType, power, account } = req.body
    let sql = " select x.*,rownum seq from ( "
    sql += " select a.asset_no,a.asset_name,a.asset_type "
    sql += " ,a.asset_qty,a.dept_code,round(a.asset_cost,2) asset_cost,a.life_in_years "
    sql += " ,round(a.remain_money,2) remain_money "
    sql += " ,b.asset_org||b.asset_floor||b.asset_location asset_location"
    sql += " ,to_char(a.get_date,'yyyy/mm/dd') get_date "
    sql += " ,rownum seq,nvl(a.status,'使用中') as status "
    sql += " ,to_char(a.start_date,'yyyy/mm/dd') start_date "
    sql += " ,to_char(end_date,'yyyy/mm/dd') end_date"
    sql += " ,nvl(b.tax_type,'N') tax_type,a.origen_asset "
    sql += " from xx_general_asset_equip_list a,xx_general_asset_location b "
    sql += " where 1 = 1 "
    sql += " and a.asset_no = b.asset_no(+) "
    sql += orgCode && " and (a.dept_code like '"+ orgCode +"%' or a.dept_code in ('SMTIO','FPCIO')) "
    sql += deptCode && " and a.dept_code = '"+ deptCode +"' "
    sql += " and asset_type = '" + assetType + "' "
    if (power !== "Admin" && account !== "xdomain\\aweiyang") {
      sql += " and a.dept_code in ( "
      sql += " select asset_dept from xx_general_asset_manager  "
      sql += " where account = '" + account + "'  ) "
    }
    sql += " order by a.dept_code,a.asset_no) x "
    callbackFn( res, oracle.connChaos,{sql})
  })

  return router
}
